package com.anpy.album.controller;

import com.anpy.album.entity.PhotoEntity;
import com.anpy.album.service.PhotoService;
import com.anpy.common.service.model.vo.ResponseMessage;
import com.anpy.common.service.model.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/photo")
public class PhotoController {

    @Resource
    private PhotoService photoService;

    @PostMapping("/save")
    public ResponseMessage<String> savePhoto(@RequestBody PhotoEntity photoEntity) {
        boolean saveResponse = photoService.savePhoto(photoEntity);
        return Result.success();
    }

    @GetMapping("/list")
    public ResponseMessage<List<Map<String,Object>>> list(Integer albumId){
       return Result.success(photoService.list(albumId));
    }

    /**
     * 根据照片ID列表批量删除照片（不校验用户ID）
     * @deprecated 建议使用 /removeByUser 接口替代，该接口会校验用户ID
     */
    @PostMapping("/remove")
    public ResponseMessage<Boolean> remove(@RequestBody List<Integer> photoIds){
        return Result.success(photoService.removePhoto(photoIds));
    }
    
    /**
     * 根据用户ID和照片ID列表批量删除照片
     * @param request 包含用户ID和照片ID列表的请求对象
     * @return 删除结果
     */
    @PostMapping("/removeByUser")
    public ResponseMessage<Boolean> removeByUser(@RequestBody com.anpy.album.dto.PhotoRemoveRequest request){
        if (request == null || request.getUserId() == null || request.getPhotoIds() == null || request.getPhotoIds().isEmpty()) {
            return Result.error("参数错误");
        }
        return Result.success(photoService.removePhotoByUserIdAndPhotoIds(request.getUserId(), request.getPhotoIds()));
    }
}
